﻿
using System;
using System.IO;
namespace NPortableEngine
{
    public abstract class NParser
    {
        protected NParser _nextParser;

        public NParser NextParser
        {
            get { return _nextParser; }
            set { _nextParser = value; }
        }

        internal void Parse(string json, ScouterBackData backData)
        {
            ParseJsonWithEx(json, backData);

            if (this._nextParser != null)
            {
                this._nextParser.Parse(json, backData);
            }
        }

        private void ParseJsonWithEx(string json, ScouterBackData backData)
        {
            if (!string.IsNullOrEmpty(json))
            {
                try
                {
                    ParseJson(json, backData);
                }
                catch (Exception ex)
                {
                    backData.IsSuccess = false;
                    backData.Msg = "Json Parse error: " + ex.Message.ToString();
                }
            }
            else
            {
                backData.IsSuccess = false;
                backData.Msg = " ParseJsonWithEx - json str is null.";
            }
        }

        public abstract void ParseJson(string json, ScouterBackData backData);
    }
}
